import subprocess
from typing import Dict, Any

async def run_cppcheck_scan(project_path: str) -> Dict[str, Any]:
    """
    运行 Cppcheck 扫描
    
    Args:
        project_path: 项目路径
        
    Returns:
        Dict[str, Any]: 扫描结果
    """
    print(f"\n开始cppcheck扫描: {project_path}")
    try:
        # 运行cppcheck扫描
        result = subprocess.run(
            ["cppcheck", "--enable=all", project_path],
            capture_output=True,
            text=True
        )
        
        # 解析结果
        issues = []
        for line in result.stdout.splitlines():
            if "warning:" in line:
                issues.append({
                    "type": "WARNING",
                    "message": line.strip(),
                    "severity": "MEDIUM"
                })
            elif "error:" in line:
                issues.append({
                    "type": "ERROR",
                    "message": line.strip(),
                    "severity": "HIGH"
                })
        
        return {
            "status": "success",
            "issues": issues
        }
        
    except Exception as e:
        print(f"cppcheck扫描出错: {str(e)}")
        return {
            "status": "error",
            "error": str(e)
        }
